package logic

import (
	"context"
	"home-view/models/mysql"

	"home-view/homerpc/homerpc"
	"home-view/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassListLogic {
	return &ClassListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassListLogic) ClassList(in *homerpc.ClassListRequest) (*homerpc.ClassListResponse, error) {
	// todo: add your logic here and delete this line

	var class mysql.Class
	var lists []*homerpc.ClassList
	var err error
	lists, err = class.ClassList(mysql.DB, in.ClassName, in, lists)
	if err != nil {
		return nil, err
	}

	return &homerpc.ClassListResponse{
		List: lists,
	}, nil
}
